<!DOCTYPE html>
<html>

<head lang="en">
    <title>游记点评</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/css/ModelCss.css"/>
</head>

<style>
    .usefulClick {
        color: #F32D27;
    }
</style>


<script>
    $(function () {
        //地址栏上的ID是评论的ID
        var params = getParams();
        if (params.id) {
            //通过评论ID 获取当前评论者的ID
            console.log(params.id);
            $.get("/comments/" + params.id, function (data) {
                console.log(data);
                $(".container").renderValues(data);
                $("#commentNum").html(data.subComms);


                //查询当前子评论数据
                $.get("/comments/" + params.id + "/ofComments", function (data) {
                    //获取子评论的回复数

                    $("#ofComment").renderValues({"list": data}, {
                        setHerf: function (ele, val) {
                            var href = $(ele).attr("href") + val;
                            $(ele).attr("href", href);
                        }
                    })
                })

                //获取子评论的点赞数
                $.get("/ofComments/travel/likeNums",{"commentId":params.id},function (data) {
                    $(".likeNum").html(data.likeNums)
                })
                console.log(data.commentator.id);


                $("#replyBtn").click(function () {
                    $("#content").val("");
                    modal.style.display = "block";
                })
                $("#cancel").click(function () {
                    modal.style.display = "none";
                })
                //确定按钮
                $("#sure").click(function () {
                    //获取文本域的内容
                    var content = $("#content").val();
                    //判断文本域中的内容是否为空
                    if (!content) {
                        $(document).dialog({
                            autoClose: 2500,
                            content: "内容不能为空",
                        });
                        return;
                    }


                    var userStr = sessionStorage.getItem("user");
                    var userJSON = JSON.parse(userStr);

                    //判断是否自己对自己进行回复
                    if (userJSON.id == data.commentator.id) {
                        $(document).dialog({
                            autoClose: 2500,
                            content: "不能对自己进行评论",
                        });
                        return;
                    }

                    var content = $("#content").val();
                    //子评论添加
                    $.ajax({
                        type: "POST",
                        url: "/ofComments/subComm",
                        data: {"comment.id": params.id, "content": content, "replier.id": userJSON.id},
                        success: function (data) {
                            if (data.success) {
                                //隐藏文本框
                                modal.style.display = "none";
                                location.reload();
                            }
                        }
                    })
                })




            })
        }





    })
</script>


<div id="modal" class="modal">
    <div class="modal-content">
        <header class="modal-header">
            <h4>请填写你的评论</h4>
        </header>
        <textarea id="content"></textarea>
        <footer class="modal-footer">
            <button id="cancel">取消</button>
            <button id="sure">确定</button>
        </footer>
    </div>
</div>


<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:" onclick="self.location=document.referrer;">
            <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>子点评详情</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<div class="comment">


    <div class="container ">
        <div class="row">
            <div class="col-2 comment-head">
                <a id="authorId" data-href="userProfiles.html" render-attr="data-id=commentator.id">
                    <img render-src="commentator.headImgUrl" class="rounded-circle">
                </a>

            </div>

            <div class="col">
                <span class="comment-date" render-html="date"></span>
                <span class="comment-img" render-html="commentator.nickName"></span>
                他的评论内容:<div class="comment-content" render-html="content">
                    <p render-html=""></p>
                </div>
                <button class="btn" id="replyBtn">回复</button>
                <button class="btn" id="followBtn">关注</button>
            </div>

        </div>
    </div>

    <div class="count d-flex justify-content-between">
        <div class="p-2">评论<span id="commentNum">0</span></div>
        <!--子点赞-->
        <div class="p-2">赞<span class="likeNum">0</span></div>
    </div>

</div>

<!--评论列表的展示-->
<span>所有回复...</span>
<div class="comment" id="ofComment">

    <div class="container" render-loop="list">
        <div class="row">
            <div class="col-2 comment-head">
                <a href="userProfiles.html?id=" render-fun="setHerf" render-key="list.commentator.id">
                    <span render-html="list.replier.nickName"></span>
                    <img class="rounded-circle" render-src="list.replier.headImgUrl">
                </a>
            </div>
            <div class="col">
                <span class="comment-date" render-html="list.date"></span>
                <div class="comment-content">
                    <p render-html="list.content"></p>
                </div>
            </div>

        </div>
    </div>

</div>


</body>


</html>